package com.idroc.cdfs.service.meta;

import java.util.Map;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.idroc.cdfs.node.INode;
import com.idroc.cdfs.node.impl.StorageNode;
import com.idroc.cdfs.node.impl.StorageNode.BerkeleyCollection;
import com.idroc.cdfs.service.INodeService;
import com.idroc.cdfs.service.data.LocalDataNodeService;
import com.sleepycat.collections.StoredMap;

/**
 * 元数据节点服务
 * @author zhandl(yuyoo4j@163.com)
 * @companay www.idroc.com
 * @2009-8-9 上午02:19:34
 */
public class MetaNodeService implements INodeService {
		
	private static final Logger log = LoggerFactory.getLogger(MetaNodeService.class);
	
	private static final String ROOT_META_NODE = "root_meta_node";

	private static final String STRORAGE_NODE = "storage_node";
	private static final String META_NODE_HOST = "meta_node_host";
	private static final String META_NODE_PORT = "meta_node_port";
	

	private LocalDataNodeService localService = new LocalDataNodeService();
	private BerkeleyCollection coll = null;
	private LocalRegistryEndpoint endpoint = null;
	
	
	public void shutdown() {
		 
	}

	public void startup() {
 
		localService.startup();
		StorageNode metaNode = localService.getMetaNode(); 
		Properties props = localService.getProps();
		String flag = props.getProperty(ROOT_META_NODE);
		String nodeNo = props.getProperty(STRORAGE_NODE);
		String host = props.getProperty(META_NODE_HOST);
		String port = props.getProperty(META_NODE_PORT);
		
		// meta node的根节点
		if ("true".equals(flag)) { 			
			endpoint = new LocalRegistryEndpoint(Integer.valueOf(nodeNo), host, Integer.valueOf(port), true, metaNode);
		} else {
			endpoint = new LocalRegistryEndpoint(Integer.valueOf(nodeNo), host, Integer.valueOf(port), false, metaNode);
		}
	}    
}
